package com.bluesky.drcp.persistence.dao.hibernate;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.bluesky.drcp.business.User;
import com.bluesky.drcp.persistence.dao.UserDao;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	public User get(String id) {

		return (User) getHibernateTemplate().get(User.class, id);
	}

	public User get(String userId, String password) {

		List list = getHibernateTemplate().find(
				"from User where id=? and password=?",
				new Object[] { userId, password });
		try {
			return (User) list.get(0);
		} catch (Exception e) {
			return null;
		}
		
	}

	public void save(User user) {
		getHibernateTemplate().save(user);
	}

	public List getAll() {
		return getHibernateTemplate().find("from User");		
	}

	public void update(User user) {
		getHibernateTemplate().update(user);		
	}

	public void delete(String userId) {
		User user = (User)getHibernateTemplate().get(User.class, userId);
		getHibernateTemplate().delete(user);		
	}
	

}
